package com.zxl.live.screen.screen.ui.widget;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zxl.live.screen.R;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Administrator on 2018/1/23.
 */

public class SystemUpdateWidget extends RelativeLayout {

    private int postion = 0;

    private ImageView mImageView;

    private TextView mTitleView;

    private TextView mMessageView;

    private ZzHorizontalProgressBar mProgressBar;

    private static Timer timer;
    private static TimerTask timerTask;

    private Handler handler = new Handler() {

        public void handleMessage(Message paramAnonymousMessage) {
            postion += 4;
            if (postion <= 100) {
                mProgressBar.setProgress(postion);
                return;
            }
            postion = 0;
            mTitleView.setText(R.string.update_error);
            mMessageView.setText(R.string.update_error_notice);
            mImageView.setImageResource(R.drawable.android_error);
            mProgressBar.setVisibility(View.INVISIBLE);
        }
    };

    public SystemUpdateWidget(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mImageView = (ImageView) findViewById(R.id.notice_pic);
        mTitleView = (TextView) findViewById(R.id.tv_update);
        mMessageView = (TextView) findViewById(R.id.tv_update_notice);
        mProgressBar = (ZzHorizontalProgressBar) findViewById(R.id.progressBar);
        timer = new Timer();
        timerTask = new TimerTask() {

            public void run() {
                handler.sendMessage(handler.obtainMessage(0));
            }
        };
        timer.schedule(timerTask, 1000L, 500L);
    }
}
